//
//  JWSignVC.m
//  jinwang
//
//  Created by jzb on 2018/3/9.
//  Copyright © 2018年 jzb. All rights reserved.
//

#import "JWSignVC.h"

@interface JWSignVC ()<UITextViewDelegate>
{
    UITextView *SignTextView;
    UILabel *placeholderLabel;//提示文字
}
@property (nonatomic,strong) UIButton *preserveBtn;

@end

@implementation JWSignVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"个性签名";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIBarButtonItem *preserveItem = [[UIBarButtonItem alloc]initWithCustomView:self.preserveBtn];
    self.navigationItem.rightBarButtonItem = preserveItem;
    
    UIView *textViewBG = [[UIView alloc]initWithFrame:CGRectMake(0, 64, kScreenWidth, 250)];
    
    textViewBG.backgroundColor = kRGBColor(238, 240, 239);
    
    [self.view addSubview:textViewBG];
    
    SignTextView = [[UITextView alloc]initWithFrame:CGRectMake(38/2, 11, kScreenWidth-76/2, 212/2)];
    
    SignTextView.delegate = self;
    
//    SignTextView.backgroundColor = [UIColor orangeColor];
    
    SignTextView.font = [UIFont systemFontOfSize:16];
    
    [textViewBG addSubview:SignTextView];
    
    SignTextView.layer.cornerRadius = 5;
    SignTextView.layer.masksToBounds = YES;
    
    if (@available(iOS 10.0, *)) {
        
        SignTextView.layer.borderColor = [UIColor lightGrayColor].CGColor;
        
    } else {
        
    }
    SignTextView.layer.borderWidth = 1;
    
    placeholderLabel = [[UILabel alloc] initWithFrame:CGRectMake(10/2, 9, kScreenWidth-100/2, 20)];
    placeholderLabel.text = @"更好的展现自己······";
    placeholderLabel.font = [UIFont systemFontOfSize:15.f];
    placeholderLabel.textColor = [UIColor lightGrayColor];
    placeholderLabel.numberOfLines = 0;
    [placeholderLabel sizeToFit];
    [SignTextView addSubview:placeholderLabel];
    
    SignTextView.text = k_user_sign;
    
    if (SignTextView.text.length > 0) {
        
        placeholderLabel.hidden = YES;
        
    }else{
        
        placeholderLabel.hidden = NO;
    }
    
}

- (void)textViewDidChange:(UITextView *)textView{
    
    if (textView.text.length > 0) {
        
        placeholderLabel.hidden = YES;
        
    }else{
        
        placeholderLabel.hidden = NO;
    }
    
}
#pragma mark -懒加载
- (UIButton *)preserveBtn{
    if (!_preserveBtn) {
        _preserveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _preserveBtn.frame = CGRectMake(0, 0, 44, 44);
        [_preserveBtn setTitle:@"保存" forState:UIControlStateNormal];
        [_preserveBtn addTarget:self action:@selector(preserveButOnclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _preserveBtn;
}

- (void)preserveButOnclick:(UIButton *)sender{
    
//    if (kStringIsEmpty(SignTextView.text)) {
//
//        [self showBottomMessag:@"请填写您的个性签名"];
//
//    }else{
        [self net_makeUrl_setUserInfo];
//    }
}
#pragma mark -网络请求

-(void)net_makeUrl_setUserInfo{
    [[DDNetworkManagerDate makeUrl_setUserInfo_with_token:k_user_token user_nickname:nil user_sex:nil user_sign:SignTextView.text user_portrait:nil] post_RequestFinshSuccess:^(id responseObject) {
        if ([self requestFinshCode:responseObject isShowMessage:YES] == 1) {
            [kUserDefaults setObject:SignTextView.text forKey:@"user_sign"];
            [self goBack];
        }
        
    } failure:^(id errorObject) {
        [self showBottomMessag:@"网络请求失败"];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
